#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    int maxSubArray(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> dp(n + 1);
        int ans = INT_MIN;
        for (int i = 1; i <= n; i++)
        {
            dp[i] = max(nums[i - 1], dp[i - 1] + nums[i - 1]);
            ans = max(ans, dp[i]);
        }

        return ans;
    }
};


int main()
{
    vector<int> nums = { -2,1,-3,4,-1,2,1,-5,4 };
    auto ret = Solution().maxSubArray(nums);
    cout << ret << endl;
    return 0;
}